package acwing_04;

import java.util.*;
import java.io.*;

public class _872_最大公约数_辗转相除法 {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int n = Integer.parseInt(br.readLine());
		int a,b,c;
	
		while(n-- > 0) {
			st = new StringTokenizer(br.readLine());
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			c = check(a,b);
			System.out.println(c);
		}
		
	}
	public static int check(int x, int y) {
		return y == 0 ? x : check(y,x % y);
	}
}
